/*
 * @Author: TT-hzy 
 * @Date: 2024-05-05 17:22:39
 * @LastEditors: TT-hzy 
 * @LastEditTime: 2024-05-05 17:22:40
 * @Description: 
 */
import 'package:easy_refresh/easy_refresh.dart';
import 'package:hzy_normal_tool/hzy_normal_tool.dart';

/// 配置结束刷新
PageState configEndRefresh({
  int? type,
  PageState? state,
  EasyRefreshController? refreshController,
}) {
  IndicatorResult result = IndicatorResult.success;

  if (state == PageState.errorState ||
      state == PageState.erroronlyTotal ||
      state == PageState.errorshowRelesh) {
    result = IndicatorResult.fail;
  } else if (state == PageState.noMoreDataState && type == 2) {
    result = IndicatorResult.noMore;
    state = PageState.dataFetchState;
  }
  if (refreshController != null) {
    if (type != 2 && refreshController.controlFinishRefresh) {
      refreshController.finishRefresh(result);
      if (state == PageState.noMoreDataState &&
          refreshController.controlFinishLoad) {
        refreshController.finishLoad(IndicatorResult.noMore);
      }
    } else if (type == 2 && refreshController.controlFinishLoad) {
      refreshController.finishLoad(result);
    }
  }
  return state ?? PageState.dataFetchState;
}
